
import axios from 'axios'
// 设置axios的前置路径
axios.defaults.baseURL = 'http://api.reyv.site/'

const defaultHeaders = {
    'Content-Type': 'application/json;charset=utf-8',
    'Access-Control-Allow-Origin': '*'
}

// 封装axios
export function request(headers = defaultHeaders, url = "/", method = "get", params = {}, data = {}) {
    axios.defaults.headers = headers
    return new Promise((resolve, reject) => {
        axios({
            url,
            method,
            params,
            data,
        }).then(res => {
            resolve(res.data)
        }, err => {
            reject(err)
        })
    })
}

export function get(url, param) { return request(defaultHeaders, url, "get", param) }

export function post(url, data, param = {}) { return request(defaultHeaders, url, "post", param, data) }
